package com.tech.connect.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.ksy.common.utils.DataUtil;
import com.tech.connect.R;
import com.tech.connect.api.BaseEntityOb;
import com.tech.connect.api.WalletHttp;

import java.util.Map;

public class WalletActivity extends BaseActivity {

    private TextView tvMoney;
    private TextView tvCoin;
    private TextView tvCharge;
    private TextView tvGet;
    private TextView tvChange;

    protected boolean isShowHeadBar() {
        return true;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getHeadBar().setTitle("钱包");
        setContentView(R.layout.activity_wallet);
        initView();
        loadData();
    }


    private void initView() {
        findViewById(R.id.tv1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jump2Activity(MyFaBuActivity.class);
            }
        });
        findViewById(R.id.tv2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jump2Activity(MyFuWuActivity.class);
            }
        });
        findViewById(R.id.tv3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jump2Activity(MyLvYouActivity.class);
            }
        });
        tvMoney = findViewById(R.id.tvMoney);
        tvCoin = findViewById(R.id.tvCoin);
        tvCharge = findViewById(R.id.tvCharge);
        tvGet = findViewById(R.id.tvGet);
        tvChange = findViewById(R.id.tvChange);
    }


    private void loadData() {
        Map<String, Object> map = WalletHttp.getMap();
        WalletHttp.info(map, new BaseEntityOb<Map<String, Float>>() {
            @Override
            public void onDataDeal(boolean isSuccess, Map<String, Float> data, String msg) {
                float have = 0.00f;
                float coin = 0;
                if (isSuccess && data != null) {
                    have = data.get("balance");
                    coin = data.get("fb");
                }
                tvMoney.setText(DataUtil.getNum(have));
                tvCoin.setText(DataUtil.getNum(coin));
            }
        });
    }

}